import React, {useEffect, useState} from 'react'
import {Button, message, Modal, Table} from 'antd'
import { connect } from 'umi'
import moment from 'moment';
import {getSysAuthorityLogByOidPage} from "../../service";

const HiredateDetails = (props) => {

  const { visible,onCancel,oid} = props
  const [data, setData] = useState([])

  useEffect(() => {
    if(oid != null){
      getSysAuthorityLogByOidPage(oid).then(res=>{
        if(res.flag){
          res.data ? setData(res.data.list.map((item, index) => {
            return { ...item, key: index }
          })) : []
        }else{
          message.error(res.error);
        }
      })
    }
  }, [oid])

  const onFormCancel = () =>{
    onCancel()
  }

  const columns = [
    {
      title: '序号',
      render:(text,record,index)=>`${index+1}`,
      hideInSearch: true,
    },
    {
      title: '修改前入职日期',
      dataIndex: 'oldData',
      key: 'oldData',
      disabled: true
    },
    {
      title: '修改后入职日期',
      dataIndex: 'newData',
      key: 'newData',
      disabled: true
    },
    {
      title: '修改人',
      dataIndex: 'updateUserName',
      key: 'updateUserName',
      disabled: true
    },
    {
      title: '操作时间',
      dataIndex: 'updateTime',
      key: 'updateTime',
      disabled: true,
      render: (text) => {
        return text ? moment(text).format('YYYY-MM-DD') : ''
      },
    },
    {
      title: '记录类型',
      dataIndex: 'type',
      key: 'type',
      render: () => {
        return '记录入职日期'
      },
    },
  ]

  const renderFooter = () => {
    return (
      <>
        <Button type="primary" onClick={() => onFormCancel()}>返回</Button>
      </>
    )
  }

  return (
    <Modal
      width={1080}
      title="入职日期修改记录"
      visible={visible}
      footer={renderFooter()}
      onCancel={() => onFormCancel()}
    >
      <Table
        columns={columns}
        dataSource={data}
        pagination={false}
      />
    </Modal>
  )
}


export default connect(() => ({
}))(HiredateDetails)
